//
//  DemoDicSort.m
//  ocdemo
//
//  Created by JIENING ZHANG on 2019/5/5.
//  Copyright © 2019 JIENING ZHANG. All rights reserved.
//

#import "DemoDicSort.h"

@implementation DemoDicSort
+ (void)demoLogic {
    NSDictionary *monthDic = @{
                               @"January" :     @(31),
                               @"February" :    @(28),
                               @"March" :       @(31),
                               @"April" :       @(30),
                               @"May" :         @(31),
                               @"June" :        @(30),
                               @"July" :        @(31),
                               @"August" :      @(31),
                               @"September" :   @(30),
                               @"October" :     @(31),
                               @"November" :    @(30),
                               @"December" :    @(31),
                               };
    
    NSArray *dicKeysSorted = [[monthDic allKeys] sortedArrayUsingComparator:^NSComparisonResult(id  _Nonnull obj1, id  _Nonnull obj2) {
        NSComparisonResult res = [((NSString *)obj1) compare:((NSString *)obj2)];
        if(res == NSOrderedAscending) {
            return NSOrderedDescending;
        } else {
            return NSOrderedAscending;
        }
    }];
    
    for(NSString *key in dicKeysSorted) {
        NSLog(@"DemoDicSort, for loop, %@ : %@", key, monthDic[key]);
    }
}

@end
